import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/material.dart';

import '../../base_page.dart';
import '../../const_config.dart';

class CustomTilePage extends BasePage {
  CustomTilePage(String title, String subTitle) : super(title, subTitle);

  @override
  Widget build(BuildContext context) {
    return _ShowCustomTilePageBody();
  }
}

class _ShowCustomTilePageBody extends StatefulWidget {
  const _ShowCustomTilePageBody({super.key});

  @override
  State<_ShowCustomTilePageBody> createState() => _ShowCustomTilePageBodyState();
}

class _ShowCustomTilePageBodyState extends State<_ShowCustomTilePageBody> {
  late AMapController _mapController;

  void onMapCreated(AMapController controller) {
    setState(() {
      _mapController = controller;
      _mapController.setCustomTile("https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}", zIndex: 10);
    });
  }

  @override
  Widget build(BuildContext context) {
    final AMapWidget map = AMapWidget(apiKey: ConstConfig.amapApiKeys, onMapCreated: onMapCreated, initialCameraPosition: CameraPosition(target: LatLng(33.672318, 119.50346), zoom: 18));
    return ConstrainedBox(constraints: BoxConstraints.expand(), child: Container(height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, child: map));
  }
}
